"""
ActionChains 执行复杂的用户操作
鼠标移动拖拽右键单击左键双击
将任务的多个操作链接为一个操作链
"""
from time import sleep
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
#创建一个浏览器实例
driver = webdriver.Chrome()
driver.get("http://www.baidu.com")

#<a href="http://www.baidu.com/more/" name="tj_briicon" class="s-bri c-font-normal c-color-t" target="_blank">更多</a>
gengduo = driver.find_element(By.NAME,"tj_briicon")
ac = ActionChains(driver)
#将鼠标移动到更多标签上
ac.move_to_element(gengduo).perform()
sleep(2)
#<a class="img-spacing" href="https://jiankang.baidu.com/widescreen/home" target="_blank" name="tj_jiankang"><img src="https://pss.bdstatic.com/static/superman/img/topnav/newjiankang-f03b804b4b.png"><div class="s-top-more-title c-font-normal c-color-t">健康</div></a>
jiankang = driver.find_element(By.NAME,"tj_jiankang")
ac.move_to_element(gengduo).move_to_element(jiankang).click().perform()
sleep(5)
driver.close()
#或者
# jk = ActionChains(driver)
# jk.move_to_element(jiankang).click().perform()
# sleep(3)
#################################################
driver.switch_to.window(driver.window_handles[0])
sleep(2)
driver.get("http://www.baidu.com")
gengduo = driver.find_element(By.NAME,"tj_briicon")
sleep(3)
jiankang = driver.find_element(By.NAME,"tj_jiankang")
sleep(3)
ac.move_to_element(gengduo).move_to_element(jiankang).click().perform()
sleep(5)
